<?php

class Api_Manager extends PhalApi_Api {

    public function getRules() {
        return array(

            'login' => array(
                'username' => array('name' => 'username', 'require' => true),
                'password' => array('name' => 'password', 'require' => true, 'min' => 6),
                ),
            'callDoctors'=>array(
                'doctor_id'=>array('name' => 'DoctorId','require' => true, 'type' => 'array', 'format' => 'explode', 'separator' => ','),
                'event_id'=>array('name'=>'EventId','require' => true)
            ),
            'dispatchDoctors'=>array(
                'doctor_id'=>array('name' => 'DoctorId','require' => true, 'type' => 'array', 'format' => 'explode', 'separator' => ','),
                'event_id'=>array('name'=>'EventId','require' => true)
            ),
            'getResponse'=>array(
                'response_id'=>array('name' => 'ResponseId', 'type' => 'array', 'format' => 'explode', 'separator' => ','),
            ),
        );
    }

	/**
     * 管理员登陆
     * @desc 管理员登陆
     * @return int code 操作码，0表示成功， 1表示用户不存在或密码错误
     * @return object info 用户信息对象
     * @return int info.id 用户ID
     * @return string info.name 用户名字
     * @return string msg 提示信息
     */
    public function login() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array('a'=>1));

        $domain = new Domain_Manager();
        $info = $domain->login($this->username,$this->password);
        var_dump($info);

        if (empty($info)) {
            DI()->logger->debug('user not found', $this->username);

            $rs['code'] = 1;
            $rs['msg'] = T('user not exists');
            return $rs;
        }

        $rs['info'] = $info;
        DI()->logger->debug('info of login', $rs);

        return $rs;

    }
    /**
         * 呼叫医生
         * @desc 给选中医生发送退送
         * @return int code 操作码，0表示成功， 1错误
         * @return object info 信息对象
         * @return string msg 提示信息
         */
    public function callDoctors() {
            $rs = array('code' => 0, 'msg' => '', 'info' => array());

            $domain = new Domain_Manager();
            $info = $domain->callDoctor($this->doctor_id,$this->event_id);

            if (empty($info)) {
                DI()->logger->debug('callDoctors()','');

                $rs['code'] = 1;
                $rs['msg'] = T('给选中医生发送退送失败');
                return $rs;
            }

            $rs['info'] = $info;
            DI()->logger->debug('info of callDoctors()', $rs);

            return $rs;

        }

    /**
         * 给医生派单
         * @desc 给医生派单
         * @return int code 操作码，0表示成功， 1错误
         * @return object info 信息对象
         * @return string msg 提示信息
         */
    public function dispatchDoctors() {
            $rs = array('code' => 0, 'msg' => '', 'info' =>array('a'=>1));

            $domain = new Domain_Manager()  ;
            $info = $domain->dispatchDoctors($this->doctor_id,$this->event_id);

            if (empty($info)) {
                DI()->logger->debug('DispatchDoctors()','');

                $rs['code'] = 1;
                $rs['msg'] = T('给医生派单失败');
                return $rs;
            }

            $rs['info'] = $info;
            DI()->logger->debug('info of DispatchDoctors()', $rs);

            return $rs;

        }
    /**
         * 获取答复
         * @desc 获取答复
         * @return int code 操作码，0表示成功， 1错误
         * @return object info 信息对象
         * @return string msg 提示信息
         */
    public function getResponse() {
            $rs = array('code' => 0, 'msg' => '', 'info' => array());

            $domain = new Domain_Manager() ;
            $info = $domain->getResponse($this->response_id);

            if (empty($info)) {
                DI()->logger->debug('getResponse()','');

                $rs['code'] = 1;
                $rs['msg'] = T('获取答复失败');
                return $rs;
            }

            $rs['info'] = $info;
            DI()->logger->debug('info of getResponse()', $rs);

            return $rs;

        }



}
 